package com.top.art.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.top.art.entity.AdmissionTicket;
import com.top.art.entity.Ruler;
import com.top.art.mapper.AdmissionTicketMapper;
import com.top.art.service.IAdmissionTicketService;
import com.top.art.tool.AuthTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import static com.top.art.tool.Tool.notNullAndEmpty;

/**
 * @description:
 * @author: huangyixin
 * @create: 2020/10/11 14:10
 **/
@Slf4j
@Service
public class AdmissionTicketServiceImpl extends ServiceImpl<AdmissionTicketMapper, AdmissionTicket> implements IAdmissionTicketService {

    @Override
    public List<AdmissionTicket> query(String province, String provinceCode) {
        return this.list(Wrappers.<AdmissionTicket>lambdaQuery()
                .eq(notNullAndEmpty(province), AdmissionTicket::getProvince, province)
                .eq(notNullAndEmpty(provinceCode), AdmissionTicket::getProvinceCode, provinceCode));
    }

    @Override
    public Boolean create(AdmissionTicket admissionTicket) {
        String account = AuthTool.currentUser().getAccount();
        admissionTicket.setCreator(account);
        admissionTicket.setCreateAt(new Date());
        admissionTicket.setModifier(account);
        admissionTicket.setModifyAt(new Date());
        return this.save(admissionTicket);
    }

    @Override
    public Boolean update(AdmissionTicket admissionTicket) {
        String account = AuthTool.currentUser().getAccount();
        admissionTicket.setModifier(account);
        admissionTicket.setModifyAt(new Date());
        return this.updateById(admissionTicket);
    }
}
